//reflect2
package main

import (
	"fmt"
	"reflect"
)

type user struct {
	name string
	age  int
}

type manager struct {
	user
	title string
}

func (user) av()  {}
func (*user) ap() {}

func (manager) bv()  {}
func (*manager) bp() {}

func main() {
	var m manager
	t := reflect.TypeOf(&m)

	if t.Kind() == reflect.Ptr {
		t = t.Elem()
	}

	//获取字段的
	for i := 0; i < t.NumField(); i++ {
		f := t.Field(i)
		fmt.Println(i, f.Name, f.Type, f.Offset)

		if f.Anonymous {
			for x := 0; x < f.Type.NumField(); x++ {
				af := f.Type.Field(x)
				fmt.Println(i, x, af.Name, af.Type)
			}
		}
	}

	t1 := reflect.TypeOf(m)

	name, _ := t1.FieldByName("name")
	fmt.Println("t1", name.Name, name.Type)

	age := t1.FieldByIndex([]int{0, 1})
	fmt.Println("t1 0 1", age.Name, age.Type)

	var b manager

	t22 := reflect.TypeOf(&b)

	s := []reflect.Type{t22, t22.Elem()}

	for _, t123 := range s {
		fmt.Println(t123, ":")

		for j := 0; j < t123.NumMethod(); j++ {
			fmt.Println(" ", j, t123.Method(j))
		}
	}
}
